package arithmetic.baseAlgorithm.sort;

/**
 * 希尔排序
 *
 * @author zhangyanqi
 * @since 1.0 2017/10/18
 */
public class ShellSort {


    public static void sort(int[] toSort,int step) {
        for (; step > 1; step--) {
            for (int i = 0; i < toSort.length - step; i++) {
                int a = toSort[i];
                int b = toSort[i + step];
                if (a > b) {
                    toSort[i] = b;
                    toSort[i + step] = a;
                }
            }
        }
    }


    public static void main(String[] args) {
        int[] ints = {3, 2, 1, 5, 7, 6};
        int step = 2;
        sort(ints,step);
        System.out.println(ints[0] + " " + ints[1] + " " + ints[2] + " " + ints[3] + " " + ints[4] + " " + ints[5]);
    }
}
